<template>
	<view class="reward-container">
		<view class="btns">
			<view class="btn1 btn" @click="handleJump('/pages/act/rules')"></view>
			<view class="btn2 btn" @click="handleJump('/pages/act/reward')"></view>
		</view>
		<view class="header">
			<view class="myheader">
				<div class="erwei" v-if="code">
					<image :src="code" mode=""></image>
				</div>
				<div class="loginBtn" @click="handleDown()">保存本地</div>
			</view>
		</view>

		<view class="header2">
			<view class="btnShare">
				<view class="btn1 btn" @click="handleShare1()"></view>
				<view class="btn2 btn" @click="handleShare1()"></view>
				<view class="btn3 btn" @click="handleOpen()"></view>
			</view>
		</view>
		<view class="header3">
			<view class="tops">
				<view class="top" :class="'index'+index" v-for="(item,index) in orderList">
					<image :src="item.avatarJson" mode=""></image>
					<view class="">
						<text>{{item.nick}}</text>
						<text style="color:RGBA(254, 56, 55, 1); margin-left: 10rpx;">{{item.money}}元</text>
					</view>
				</view>

			</view>

		</view>
		<view class="header4">
			<view class="text">
				<view class="content" v-if="wenan">
					<view class="li" v-for="(i, ind) in wenan" :key="ind">
						{{
							i
						}}
					</view>
				</view>
			</view>
		</view>
		<!-- 分享弹框 -->
		<uni-popup ref="popupShare" type="center" :mask="true" :mask-click="false">
			<view class="marks column">
				<view class="im"></view>
				<!-- <image src=""></image> -->
				<image class="img" :src="code"></image>
				<view class="cancel" @click="closePopup"></view>
			</view>

		</uni-popup>
		<!-- <view class="wrapper">
			
			<view class="footer">
				<view class="context">
					<view class="li">
						1、身份为护士小鹿平台的注册护士（以下称为推荐人）可参与本活动。
					</view>
					<view class="li">
						1、身份为护士小鹿平台的注册护士（以下称为推荐人）可参与本活动。
					</view>
					<view class="li">
						1、身份为护士小鹿平台的注册护士（以下称为推荐人）可参与本活动。
					</view>
				</view>
				<view class="inner ">
						<view class="shenmin">相关声明</view>
						<view class="text">若出现以不正当手段（包括但不限于批量注册、用户机器注册账户、机器模拟客户端、账号买卖、作弊扰乱系统获取新人券和活动奖励，违反《护士小鹿用户协议》等，均可能会被系统视为风险账户，您将不会获得奖励，护士小鹿有权取消用户参与本次活动的资格，并对其账号进行封禁同时有权撤销违规交易，并回收活动中已经发放到余额的奖励，保留拒绝赋予其今后参加本公司任何优惠活动的权利，并追究相关法律责任。护士小鹿可在法律法规的允许范围内，对本次活动调整修改。</view>
					
				</view>
				
			</view>
		</view> -->

	</view>
</template>

<script>
	import UniShare from '@/uni_modules/uni-share/js_sdk/uni-share.js';
	import * as api from '@/apis/invite/index.js'
	import uniPopup from '../../components/uni-ui/uni-popup/uni-popup.vue';
	const uniShare = new UniShare();
	export default {
		data() {
			return {
				code: '',
				url: '',
				orderList: [],
				wenan: ''
			}
		},

		components: {
			uniPopup,
		},
		async onLoad() {
			// uni.showLoading({
			// 	title:'加载中'
			// })
			// 获取二维码
			await this.init()
			// 获取前三排名
			this.getThree()

			// this.wenan = this.$store.state.myInviteObj.wenan
		},
		onShow() {
			// this.$nextTick(()=> {
			// 	this.$refs.popupShare.open()
			// })
		},
		onBackPress({
			from
		}) {
			console.log(from);
			if (from == 'backbutton') {
				this.$nextTick(function() {
					uniShare.hide()
				})
				return uniShare.isShow;
			}
		},
		methods: {

			async init() {
				let info = this.$store.state.userInfo
				let {
					avatarJson,
					mobile
				} = info
				api.registerAndSaveLog({
					imageUrl: avatarJson,
					mobile
				}).then(r => {
					this.code = r.object.path
					this.url = r.object.url
					uni.hideLoading();
				})
			},

			getThree() {

				api.nurseInviteUser().then(r => {
					let arr = r.object
					let ob = arr.shift()
					arr.splice(1, 0, ob)
					this.orderList = [...arr]

					this.wenan = (r.object[0].awardExplain).split('\n')
				})
				// api.selectRule().then(r => {
				// 	this.wenan = r.object.awardExplain.split('\n')
				// })
			},
			handleJump(url) {
				uni.navigateTo({
					url
				})
			},
			handleShare1() {
				console.log(UniShare)
				// const uniShare = new UniShare();
				console.log(uniShare)
				let that = this
				uniShare.show({
					content: { //公共的分享参数配置  类型（type）、链接（herf）、标题（title）、summary（描述）、imageUrl（缩略图）
						type: 0,
						// 	type: 0,
						href: that.url,
						title: "快来加入护士小鹿！",
						summary: "注册成功即可领取现金红包奖",
						imageUrl: 'http://loto.oss-cn-shanghai.aliyuncs.com/service/4d566e7a3f174f61.png'
					},
					menus: [{
							"img": "/static/img/mine/weixin.png",
							"text": "微信好友",
							"share": { //当前项的分享参数配置。可覆盖公共的配置如下：分享到微信小程序，配置了type=5
								"provider": "weixin",
								"scene": "WXSceneSession"
							}
						},
						{
							"img": "/static/img/mine/friend.png",
							"text": "微信朋友圈",
							"share": {
								"provider": "weixin",
								"scene": "WXSceneTimeline"
							}
						}
					],
					cancelText: uni.getSystemInfoSync().platform == "android" ? "取消分享" : '',
				}, e => { //callback
					console.log(uniShare.isShow);
					console.log(e);
				})
			},

			handleOpen() {
				this.$refs.popupShare.open()
			},
			closePopup() {
				this.$refs.popupShare.close()
			},
			handleDown() {
				uni.saveImageToPhotosAlbum({
					filePath: this.code,
					success: function() {
						uni.showToast({
							title: '保存成功！'
						})
					},
					fail: function() {
						uni.showToast({
							title: '请检查访问相册权限！'
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.reward-container {
		min-height: 100vh;
		box-sizing: border-box;
	}

	.btns {
		position: absolute;
		right: 0;
		z-index: 99;

		.btn {
			opacity: 0;
			width: 200rpx;
			height: 70rpx;
			// background-color: yellow;

			&.btn2 {
				margin-top: 30rpx;
			}
		}
	}

	.header {
		position: relative;
		width: 750rpx;
		height: 1290rpx;
		background: url('/../../../static/img/reward/index1.png');
		background-size: 100% 100%;
	}

	.header2 {
		position: relative;
		width: 750rpx;
		height: 790rpx;
		background: url('/../../../static/img/reward/index2.jpg');
		background-size: 100% 100%;

		.btnShare {
			position: absolute;
			top: 13%;
			padding: 0 8%;
			width: 80%;
			display: flex;
			justify-content: space-between;

			.btn {
				opacity: 0;
				width: 150rpx;
				height: 150rpx;
				// background-color: yellow;
			}
		}
	}

	.header3 {
		position: relative;
		width: 750rpx;
		height: 450rpx;
		background: url('/../../../static/img/reward/index3.jpg');
		background-size: 100% 100%;
		display: flex;
		justify-content: center;

		.tops {
			position: absolute;
			top: 140rpx;
			display: flex;

			.top {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				&.index0 {
					position: relative;
					top: 50rpx;

					// border: 2rpx red solid;
				}

				&.index1 {
					position: relative;
					margin: 0 90rpx;

					// border: 2rpx red solid;
				}

				&.index2 {
					position: relative;
					top: 50rpx;
					// border: 2rpx red solid;
				}
			}


			image {
				height: 80rpx;
				width: 80rpx;
				border-radius: 50%;
			}
		}
	}

	.header4 {
		position: relative;
		width: 750rpx;
		height: 390rpx;
		background: url('/../../../static/img/reward/index4.jpg');
		background-size: 100% 100%;

		.text {
			position: absolute;
			overflow: scroll;
			height: 260rpx;
			margin: 90rpx 80rpx 0;
		}
	}

	.wrapper {
		background-color: rgba(247, 247, 247, 1);
		// padding: 0 20rpx;
	}

	.footer {
		position: relative;
		top: -224rpx;
		margin: 0 20rpx;
		padding: 34rpx 0;
		background: #FFFFFF;
		border-radius: 16rpx;

		.context {
			font-size: 28rpx;
			color: #333333;
			margin: 62rpx 28rpx 70rpx;

			.li {
				margin-bottom: 16rpx;
			}
		}

		.inner {
			margin: 0rpx 28rpx;
			padding: 42rpx 34rpx;
			background: #F6F6F6;
			border-radius: 16px;

			.shenmin {
				margin-bottom: 16rpx;
				text-align: center;
				font-size: 36rpx;
				color: #333333;
			}

			.text {
				font-size: 24rpx;
				color: #333333;
				line-height: 40rpx;
			}
		}
	}

	.marks {
		position: relative;
		width: 644rpx;
		height: 1022rpx;

		.im {
			position: absolute;
			width: 100%;
			height: 100%;
			background: url('/../../../static/img/reward/erweima.jpg');
			background-size: 100% 100%;
		}

		.cancel {
			opacity: 0;
			position: absolute;
			bottom: 0;
			right: 40%;
			height: 160rpx;
			width: 120rpx;
			// background: yellow;
			text-align: right;
			color: #FFF;
			font-size: 48rpx;

		}

		image {
			height: 100%;
			width: 100%;
		}

		.img {
			position: absolute;
			top: 52%;
			left: 32%;
			width: 220rpx;
			height: 220rpx;
		}
	}

	.myheader {
		// padding: 0 13.3%;
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		position: absolute;
		bottom: 7%;
		box-sizing: border-box;

		.erwei {
			height: 260rpx;
			width: 260rpx;

			// background: yellow;

			image {
				height: 100%;
				width: 100%;
				border: 16rpx solid #FFF;
			}
		}
	}

	.loginBtn {
		position: relative;
		left: 16rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 60rpx 0 0rpx;
		padding: 8rpx 0px;
		width: 400rpx;
		// height: 50rpx;
		background: RGBA(255, 231, 164, 1);
		border-radius: 25px;
		font-size: 38rpx;
		font-weight: 500;
		color: RGBA(255, 36, 36, 1);
		box-sizing: border-box;
	}
</style>